package miniqq.thread;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.UnknownHostException;

import android.os.Handler;
import android.os.Message;
import android.os.StrictMode;

public class ConnectSocketThread extends Thread{
	Socket socket = new Socket();
	Handler handler = null;
	
	public ConnectSocketThread(Handler _handler){
		handler = _handler; 
	}
	
	public void run(){
		while(true){
			if(!socket.isConnected()){
				StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().
	               detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
				SocketAddress serverIp = new InetSocketAddress("nat.nat123.net", 13148);
				try {
					socket.connect(serverIp, 5000);
					Message msg = Message.obtain();
					msg.what = -1;
					msg.obj = socket;
					handler.sendMessage(msg);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
